package com.hmall.order.web;

import com.hmall.dto.OrderDTO;
import com.hmall.order.service.IOrderDetailService;
import com.hmall.pojo.Order;
import com.hmall.order.service.IOrderService;
import com.hmall.pojo.OrderDetail;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("order")
@Slf4j
public class OrderController {

   @Autowired
   private IOrderService orderService;


   @GetMapping("{id}")
   public Order queryOrderById(@PathVariable("id") Long orderId) {
      Order order = orderService.getById(orderId);
      log.info("订单id：{}",orderId);
      return order;
   }

   /**
    * 创建订单
    * @param orderDTO
    * @return
    */
   @PostMapping
   public Map<String,String> createOrder(@RequestBody OrderDTO orderDTO){
      log.info("创建订单：{}",orderDTO);
      Long id = orderService.createOrder(orderDTO);

      Map<String,String> map = new HashMap<>();
      map.put("id",id.toString());
      return map;
   }

   /**
    * 根据id更新order表
    * @param order
    */
   @PutMapping("/update")
   public void updateOrder(@RequestBody Order order){
      orderService.updateById(order);
   }
}
